import os from 'os'
import * as address from 'address'
import { BrowserWindow, screen } from 'electron'

export default [
  {
    channel: 'context',
    type: 'handle',
    cb: () => {
      console.log('-----> context')
      return {
        ip: address.ip(),
        no: os.hostname(),
        store_id: 3,
        store_name: '华润店'
      }
    }
  },
  {
    channel: 'close',
    type: 'on',
    cb: (mainWindow: BrowserWindow) => {
      const printWidth = screen.getPrimaryDisplay().workAreaSize.width
      const printHeight = screen.getPrimaryDisplay().workAreaSize.height
      mainWindow.setResizable(true)
      mainWindow.setSize(365, 126)
      mainWindow.setPosition(Math.floor((printWidth - 365) / 2), printHeight - 226)
      mainWindow.setResizable(false)
    }
  },
  {
    channel: 'open',
    type: 'on',
    cb: (mainWindow: BrowserWindow) => {
      // const printWidth = screen.getPrimaryDisplay().workAreaSize.width
      // const printHeight = screen.getPrimaryDisplay().workAreaSize.height
      mainWindow.setResizable(true)
      mainWindow.setSize(1248, 826)
      // mainWindow.setPosition(
      //   Math.floor((printWidth - 1248) / 2),
      //   Math.ceil((printHeight - 826) / 2) + 200
      // )
      mainWindow.center()
      mainWindow.setResizable(false)
    }
  }
]
